# -*- coding: utf-8 -*-
"""
@Time: 2021/12/10 10:51
@Author: jins
@File: table_uelectricityd.py
@Introduction: uelectricityd表造数据
"""
from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta

EfficacyOptions_list = [1, 2, 4, 8]
PhaseOptions_list = [1, 2, 4, 8, 16]
combination_list = [(i, j) for i in EfficacyOptions_list for j in PhaseOptions_list]


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        for k in combination_list:
            data_time_origin = datetime(2021, 11, 1, 0, 0, 0)
            fmt = '%Y%m%d'
            PikeValue = random.uniform(1000.0, 1200.0)
            PeakValue = random.uniform(1000.0, 1200.0)
            FlatValue = random.uniform(1000.0, 1200.0)
            ValeValue = random.uniform(1000.0, 1200.0)
            TotalValue = PikeValue + PeakValue + FlatValue + ValeValue
            for i in range(30):
                unit_id = 10000000 + j
                data_time = data_time_origin.strftime(fmt)
                increase_num = random.uniform(5.0, 10.0)
                PikeProportion = (PikeValue / TotalValue)
                PeakProportion = (PeakValue / TotalValue)
                FlatProportion = (FlatValue / TotalValue)
                ValeProportion = (ValeValue / TotalValue)
                UpdateTime = data_time_origin.timestamp()*1000
                sql = f"""INSERT INTO xlcloud.uelectricityd21b
                VALUES
                    (   
                        {unit_id},
                        1,
                        {data_time},
                        {k[0]},
                        {k[1]},
                        {TotalValue},
                        {PikeValue},
                        {PeakValue},
                        {FlatValue},
                        {ValeValue},
                        {PikeProportion},
                        {PeakProportion},
                        {FlatProportion},
                        {ValeProportion},
                        2,
                        0,
                        {UpdateTime}
                    )
                        """
                op.batch_excute(sql)
                data_time_origin += timedelta(days=1)
                PikeValue += increase_num
                PeakValue += increase_num
                FlatValue += increase_num
                ValeValue += increase_num
            op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)
